<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/8/13
  Time: 10:28
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>修改学生</title>
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="css/update_stu.css"/>
    <script type="text/javascript" src="js/jquery-3.1.1.js"></script>
    <script type="text/javascript" src="js/bootstrap.min.js"></script>
</head>
<body>
<!--页面显示-->

<div id="stu_show">
    <form action="" method="post">
        <input type="hidden" name="stu_id" value="${sessionScope.item.stu_id}">
        <table id="stu_info">
            <tr>
                <td>学号</td>
                <td>姓名</td>
                <td>性别</td>
                <td>系别</td>
                <td>班级</td>
                <td>电话</td>
                <td>邮箱</td>
                <td>操作</td>
            </tr>
            <tr>
                <!--学号-->
                <td >
                    <p name="stu_no">${sessionScope.item.stu_no}</p>
                </td>
                <!--姓名-->
                <td>
                    <input type="text" name="stu_name"  value="${sessionScope.item.stu_name}" />
                </td>
                <!--性别-->
                <td>
                    <c:if test="${sessionScope.item.stu_sex=='男'}">
                    <select name="stu_sex">
                        <option value="男">男</option>
                        <option value="女">女</option>
                    </select>
                    </c:if>
                    <c:if test="${sessionScope.item.stu_sex=='女'}">
                        <select name="stu_sex">
                            <option value="女">女</option>
                            <option value="男">男</option>
                        </select>
                    </c:if>
                </td>

                <!--系别-->
                <td>
                    <select name="d_id" onchange="selectClass()" id="dept">
                        <option value="">---选择系别---</option>
                        <c:forEach var="dept" items="${sessionScope.dept}">
                        <option value="${dept.d_id}">${dept.d_name}</option>
                        </c:forEach>
                    </select>

                </td>
                <!--班级-->
                <td>
                    <select name="c_id" id="class">
                        <option value="">-----选择班级-----</option>

                    </select>
                </td>
                <!--电话-->
                <td>
                    <input type="text" name="stu_tel"  value="${sessionScope.item.stu_tel}" />
                </td>
                <!--邮箱-->
                <td>
                    <input type="email" name="stu_email"  value="${sessionScope.item.stu_email}"/>
                </td>
                <td>
                    <button type="submit" class="btn btn-info" formaction="${pageContext.request.contextPath}/W_UpdateStuServlet">修改</button>
                </td>
            </tr>
        </table>

    </form>
</div>
</body>
<script type="text/javascript">

    //
    function selectClass() {
        var d_id=$("#dept").val();

        jQuery.post("${pageContext.request.contextPath}/AjaxClassServlet",{"d_id":d_id},function (date) {
            var option="";
            jQuery.each(date,function (i, item) {
                //value
                option+="<option value='";
                //数据库SQL尽量大写,
                option+=item.C_ID; //加上""就变成原意字符串了,要他的值就不能加双引号
                option+="'>";
                //显示
                option+=item.C_NAME;
                option+="</option>";
            });
            jQuery("#class").html(option);

        },"JSON");
    }
</script>
</html>